package com.weishui.talking.app;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.EventQueue;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.border.LineBorder;
import javax.swing.border.TitledBorder;

import com.jtattoo.plaf.mcwin.McWinLookAndFeel;
import com.weishui.talking.listener.ButtonActionListener;
import com.weishui.talking.socket.Serversocket;

public class TalkingWindow extends AbstractPanle{

	public JTextArea textAreaMessage;
	public JIpAddressField jIpAddressField;
	
	//当前目录
	String proPath = System.getProperty("user.dir");
	ImageIcon imageTalking = new ImageIcon(proPath + "/image/talking2.png");
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JFrame frame;

	/**
	 * Launch the application
	 * @param args
	 */
	public static void main(String args[]) {
		Thread socketThread = new Thread(new Serversocket());
		socketThread.start();
		try {
			UIManager.setLookAndFeel(new McWinLookAndFeel());
		} catch (UnsupportedLookAndFeelException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					TalkingWindow window = new TalkingWindow(new JFrame(), true);
					window.frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application
	 */
	public TalkingWindow(JFrame owner, boolean modal) {
		super(owner, true);
		createContents();
	}

	/**
	 * Initialize the contents of the frame
	 */
	private void createContents() {
		frame = new JFrame();
		frame.getContentPane().setLayout(null);
		frame.setBounds(100, 100, 691, 563);
		frame.setIconImage(imageTalking.getImage());
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setLocationRelativeTo(null);
		frame.setResizable(false);
		frame.setTitle("Talking...");
		frame.setBackground(Color.GREEN);

		final JPanel panelLog = new JPanel();
		panelLog.setBorder(new TitledBorder(null, "日志", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, null));
		panelLog.setLayout(new BorderLayout());
		panelLog.setBounds(10, 10, 663, 306);
		panelLog.add(jsPan);
		frame.getContentPane().add(panelLog);

		final JPanel panelMessage = new JPanel();
		panelMessage.setLayout(null);
		panelMessage.setBorder(new TitledBorder(null, "消息", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, null));
		panelMessage.setBounds(10, 322, 663, 162);
		frame.getContentPane().add(panelMessage);

		textAreaMessage = new JTextArea();
		textAreaMessage.setBorder(new LineBorder(Color.black, 1, false));
		textAreaMessage.setBounds(10, 21, 643, 131);
		textAreaMessage.setLineWrap(true);
		panelMessage.add(textAreaMessage);

		final JButton buttonClear = new JButton();
		buttonClear.setText("清空");
		buttonClear.setBounds(455, 495, 84, 21);
		buttonClear.setActionCommand("clear");
		buttonClear.addActionListener(new ButtonActionListener(this));
		frame.getContentPane().add(buttonClear);

		final JButton buttonSend = new JButton();
		buttonSend.setText("发送");
		buttonSend.setBounds(565, 495, 84, 21);
		buttonSend.setActionCommand("send");
		buttonSend.addActionListener(new ButtonActionListener(this));
		frame.getContentPane().add(buttonSend);

		final JLabel ipLabel = new JLabel();
		ipLabel.setText("IP:");
		ipLabel.setBounds(20, 495, 14, 18);
		frame.getContentPane().add(ipLabel);

		jIpAddressField = new JIpAddressField();
		jIpAddressField.setBounds(40, 495, 206, 21);
		frame.getContentPane().add(jIpAddressField);
	}

}
